;(function ($) {

	/* FEATURED */
    $.changeFeatured = function () {
        if ($.changeFeatured.y === 1) {
            $('.featuredDots li').animate({
                "opacity": "0.2"
            });
            $('#featured .slide').fadeOut(1000);
            if ($.changeFeatured.x > $.changeFeatured.z) {
                $.featured(1);
                $.changeFeatured.x = 2;
            } else {
                $.featured($.changeFeatured.x);
                $.changeFeatured.x++;
                if ($.changeFeatured.x > $.changeFeatured.z) {
                    $.changeFeatured.x = 1;
                };
            };
        };
    };
	$.extend(
		$.changeFeatured,
		{
			x: 2,
			y: 1,
			z: 0
		}
	);
	
    $.featured = function (number) {
        $('.featuredDots li.dot' + number).animate({
            "opacity": "1.0"
        });
        $('#featured .slide blockquote').hide();
        $('#featured .slide' + number + ' blockquote').fadeIn();
        $('#featured .slide' + number).fadeIn(1000);
        $('#featured .slide' + number + ' .image').css({
            "left": "960px"
        });
        $('#featured .slide' + number + ' .image').animate({
            "left": "0px"
        }, 500);
    };
	
    $(window).ready(function () {
        $('#innerbanner').css('background-color', $('body').css('background-color'));
        $.changeFeatured.z = $('ul#featured li').size(); /* Number of items on featured */
		
        /* FEATURED */
        $('.featuredDots li a').click(function () {
            $('.featuredDots li').animate({
                "opacity": "0.2"
            });
            $(this).parent('li').animate({
                "opacity": "1.0"
            });
            $('#featured .slide').fadeOut(1000);
            $.changeFeatured.y = 0;
        });
		
        $('.featuredDots li a').click(function () {
            $.featured($(this).parent().attr('class').match(/\d/));
            return false;
        });
		
        setInterval("jQuery.changeFeatured()", 8000);
		
		/* TABPOSTS */
        $('.postContainer .posts').css({
            "height": "310px"
        });
		
        $('.postContainer .posts ul')
			.css({
				"position": "absolute"
			})
			.hide()
			.filter('.tab1')
				.show();
        $('ul.dots').css({
            "display": "block"
        });
		
        $('#contentarea .postContainer .posts ul')
			.hide()
			.filter('.tab1')
			.show();
		
		$('#contentarea .postContainer').each( function() {
			var $postContainer = $(this);
			var tabs = (1 - $postContainer.find('.tab').size());
			if (tabs > 0) {
				$postContainer.find('.dot:gt(' + tabs + ')').hide();
			} else {
				$postContainer.find('.dot').hide();
			};
		});
		
        $('.postContainer .heading .dots .dot a').click(function () {
            var $that = $(this);
            var $dot = $that.parent();
            $dot.siblings('.dot').removeClass('active').fadeTo('fast', 0.5, function () {
                $dot.addClass('active').removeAttr('style');
            });
            var tab = $dot.index() + 1;
            var $tabs = $(this).closest('.postContainer').find('.tab');
            var $tab_visible = $tabs.filter(':visible');
            if ($tab_visible.hasClass('tab' + tab)) {
                return false;
            }
            $tab_visible.fadeOut();
            $tabs.filter('.tab' + tab).fadeIn();
            return false;
        });
		
		/* lazyload */
        if ($.isFunction($.lazyload)) {
            $(".post img").lazyload({
                effect: "fadeIn",
                placeholder: window.placeholdergif
            });
        };
		
		/* Alinhas colunas */
		var $sidebar = $('#sidebar');
		if ($sidebar.is(':visible')) {
			var $contentarea = $('#contentarea');
			var colluns = {
				'content': $contentarea.height(),
				'sidebar': $sidebar.height()
			};
			if (colluns.content < colluns.sidebar) {
				$contentarea.height(colluns.sidebar);
			}
		};
    });
})(jQuery);